package cn.zjutleo.village_server.mapper;

import cn.zjutleo.village_server.entity.EchartsRepairApplyData;
import cn.zjutleo.village_server.entity.ViewDispatchRepairInfo;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: 张坤
 * @DateTime: 2021/8/31 19:48
 * @Description: 该类用于 TODO
 */
public interface ViewDispatchRepairInfoMapper {
    @Select("select * from viewdispatchrepairinfo where ra_id=#{ra_id}")
    @Results(id = "Base_ViewDispatchRepairInfo_Data",value = {
            @Result(property = "ra_id",  column = "ra_id",id = true),
            @Result(property = "u_village_id",  column = "u_village_id"),
            @Result(property = "ra_state",  column = "ra_state"),
            @Result(property = "rt_role",  column = "rt_role"),
            @Result(property = "dr_status",  column = "dr_status"),
            @Result(property = "u_id",  column = "u_id"),
            @Result(property = "dr_id",  column = "dr_id"),
            @Result(property = "ra_apply_time",  column = "ra_apply_time"),
            @Result(property = "dr_time",  column = "dr_time"),
            @Result(property = "u_true_name",  column = "u_true_name"),
            @Result(property = "u_phone",  column = "u_phone"),
            @Result(property = "v_name",  column = "v_name"),
            @Result(property = "u_residence_address",  column = "u_residence_address"),
            @Result(property = "v_address",  column = "v_address"),
            @Result(property = "ra_type",  column = "ra_type"),
            @Result(property = "ra_contact",  column = "ra_contact"),
            @Result(property = "rt_name",  column = "rt_name"),
            @Result(property = "rt_contact",  column = "rt_contact"),
            @Result(property = "ra_detail_address",  column = "ra_detail_address"),
            @Result(property = "rt_name",  column = "rt_name"),
            @Result(property = "rt_contact",  column = "rt_contact"),

    })
    ViewDispatchRepairInfo selectViewDispatchRepairInfo(Integer ra_id);

    @Select("select * from viewdispatchrepairinfo")
    @ResultMap("Base_ViewDispatchRepairInfo_Data")
    List<ViewDispatchRepairInfo> selectAll();

    @Select("select distinct ra_detail_address\n" +
            "from viewdispatchrepairinfo\n" +
            "where ra_detail_address like '%${fuzzySearch}%'")
    List<String> selectAddress(String fuzzySearch);

    @Select("select  ra_type,count(ra_type) as number\n" +
            "from viewdispatchrepairinfo\n" +
            "where ra_detail_address like '%${address}%'\n" +
            "group by ra_type")
    @Results(id="Base_repairApplyData_Data",value = {
            @Result(property = "repairType",  column = "ra_type"),
            @Result(property = "number",  column = "number"),
    })
    List<EchartsRepairApplyData> selectRepairApplyDataByAddress(String address);
}
